<template>
  <div class="hello" ref="row">
    <div class="haha">
      <p class="city">当前城市</p>
      <div class="city-top">
        <ul>
          <li>北京</li>
        </ul>
      </div>
      <div>
        <p class="city">热门城市</p>
        <div class="city-rm">
          <ul class="city-item">
            <li v-for="(v, i) in hotCityList" :key="i" @click="citys(v.name)">{{v.name}}</li>
          </ul>
        </div>
      </div>
      <div class="content-city" v-for="(v, i) in cityList" :key="i" :ref="i">
        <p class="city">{{i}}</p>
        <div>
          <ul>
            <li v-for="(item, index) in v" :key="index"  @click="citys(item.name)">{{item.name}}</li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Bscroll from "better-scroll";
export default {
  name: "CityContent",
  data() {
    return {};
  },
  props: ["hotCityList", "cityList", "keys"],
  mounted() {
    this.scroll = new Bscroll(this.$refs.row);
  },
  methods: {
    citys(name){
      this.$store.dispatch('cityKeys',name)
      this.$router.push('/')
      // this.$store.commit('citys',name)
      // this.$store.state.city = name
    }
  },

  //点击右边字母跳到指定位置
  watch: {
    keys(v, i) {
      // console.log(this.$refs.D[0]);
      this.scroll.scrollToElement(this.$refs[v][0],200)
      // console.log(v);
    }
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.hello {
  overflow: hidden;
  position: absolute;
  top: 1.4rem;
  left: 0;
  bottom: 0;
  width: 100%;
}
.city {
  background-color: #ccc;
  height: 0.35rem;
  line-height: 0.35rem;
  padding: 0 0.2rem;
  font-size: 13px;
  font-weight: 600;
}
.city-top ul {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
}
.city-top li {
  width: 25%;
  border: 2px solid #ccc;
  text-align: center;
  margin: 0.2rem 0;
  height: 0.4rem;
  line-height: 0.4rem;
  font-size: 12px;
  font-weight: 600;
  border-radius: 2px;
  margin-right: 5%;
}
.city-top,
.city-rm {
  padding: 0 0.2rem;
}

.city-rm li {
  width: 25%;
  border: 2px solid #ccc;
  text-align: center;
  margin: 0.2rem 0 0 0;
  height: 0.4rem;
  line-height: 0.4rem;
  font-size: 12px;
  font-weight: 600;
  border-radius: 2px;
  margin-right: 5%;
}
.city-item {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
}
.content-city {
  margin-top: 0.2rem;
}
.content-city ul {
  display: flex;
  flex-direction: column;
}
.content-city ul li {
  height: 0.5rem;
  padding: 0 0 0 0.2rem;
  border: 1px solid #ccc;
  line-height: 0.5rem;
}
</style>
